//使用机构活动模板
exports.UseOrganizationBulkPurchaseTemplate = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    //任务流创建
    async.waterfall([
            //机构模板活动
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url:CORE_APIConfig.coreAPI.searchOrganizationActivityTemplate+"/oat_id/"+restfulParams.oat_id ,
                        method: 'GET',
                    },
                    function (err,data) {
                        if(err){
                            return cb(err,data);
                        }
                        resultData.template = data.data;
                        cb();
                    }
                )
            },
            //查询皮肤信息
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url:CORE_APIConfig.coreAPI.searchActivitySkin +"/as_id/" + resultData.template[0].oat_skin_id,
                        method: 'GET',
                    },
                    function (err,data) {
                        if(err){

                            return cb(err,data);
                        }
                        resultData.skinData = data.data
                        cb();
                    }
                )
            },
            //查询音乐信息
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url:CORE_APIConfig.coreAPI.searchActivityMusic +"/am_id/" + resultData.template[0].oat_music_id,
                        method: 'GET',
                    },
                    function (err,data) {
                        if(err){

                            return cb(err,data);
                        }
                        resultData.musicData = data.data
                        cb();
                    }
                )
            },
            //查询封面信息
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url:CORE_APIConfig.coreAPI.searchActivityCover +"/ac_id/" + resultData.template[0].oat_cover_id,
                        method: 'GET',
                    },
                    function (err,data) {
                        if(err){

                            return cb(err,data);
                        }
                        resultData.coverData = data.data
                        cb();
                    }
                )
            },

            //机构模板活动拓展
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.searchBulkPurchaseActivityTemplate+"/bpac_oatid/"+restfulParams.oat_id ,
                        method: 'GET',
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }
                        resultData.extend = data.data;
                        cb();
                    }
                );
            },
            //机构模板活动内容
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url:CORE_APIConfig.coreAPI.searchBbulkPpurchaseAactivityTemplateContent+"/bpac_oatid/"+restfulParams.oat_id+"/sort_order/bpac_order-asc" ,
                        method: 'POST',
                        data : {
                            fields : [
                                "bpac_type as type",
                                "bpac_content as content"
                            ].join(",")
                        }
                    },
                    function (err,data) {
                        if(err){
                            return cb(err,data);
                        }
                        resultData.content = data.data;
                        cb();
                    }
                )
            },
        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}